package com.wondersgroup.core.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.wondersgroup.core.mapper.SysLoginUserMapper;
import com.wondersgroup.core.model.SysLoginUser;

@Service
public class SysLoginUserService {
	@Autowired
	private SysLoginUserMapper sysLoginUserMapper;
	/*
	 * 分页查询
	 * @param pageNum,pageSize
	 * @return
	 */
     
	public List<SysLoginUser> findAll(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<SysLoginUser> sysLoginUser = sysLoginUserMapper.select(null);
		return sysLoginUser;
	}
    /*
     * 根据username查询
     * @param username
     * @return 
     */
	public SysLoginUser findByuserName(SysLoginUser username){
		return sysLoginUserMapper.selectLoginUserByUserName(username);
	}
     /*
      *根据username删除 对象
      *@param username
      *@return
      */
	public int deleteByuserName(String username){
		return sysLoginUserMapper.deleteByPrimaryKey(username);
	}
	/*
	 * 添加对象
	 * @param sysLoginUser
	 * @return
	 */
	public int addUser(SysLoginUser sysLoginUser) {
		sysLoginUser.setCreateDate(new Date());
		sysLoginUser.setLastModifiedDate(new Date());
		return sysLoginUserMapper.addUser(sysLoginUser);
		
	}
	public int insertUser(SysLoginUser user){
		user.setCreateDate(new Date());
		user.setLastModifiedDate(new Date());
		return sysLoginUserMapper.insert(user);
	}

	
	/*
	 * 根据username修改对象
	 * @param username
	 * @return
	 */
	public int update(SysLoginUser username){
		username.setCreateDate(new Date());
		username.setLastModifiedDate(new Date());
		return sysLoginUserMapper.updateByPrimaryKey(username);
	} 
	/*
	 * 分页查询中查询总页数
	 */
	public int selectCount(){
		return sysLoginUserMapper.selectCount(null);
	}


}
